<?php

namespace Itwmw\Attributes\Validate;

use Itwmw\Validate\Support\Rule\BaseRule;

/**
 * 自定义验证规则
 *
 * @internal
 */
class CustomRule extends BaseRule
{
    protected \Closure $ruleClosure;

    protected array $params = [];

    public function setRuleClosure(\Closure $closure): void
    {
        $this->ruleClosure = $closure;
    }

    public function setParams(array $params): void
    {
        $this->params = $params;
    }

    public function passes($attribute, $value): bool
    {
        return ($this->ruleClosure)($attribute, $value, ...$this->params);
    }
}
